Repository navigation
fix(codegen-base): record JVM template and docs output in the hash manifest - #629
Merged
Merged
Conversation
…st; gate every write through GeneratedFileWriter Template, mustache, documentation and META-INF/services output now goes through GeneratedFileWriter.writeUnmarked, so it is recorded in the hash manifest, unchanged bytes are not rewritten and a hand edit is refused by name, while an unrecorded existing file is adopted rather than refused for lacking a marker it cannot carry. WritePathGateTest fails when generator source or the Maven plugin writes a file any other way. metaobjects:eject -Dforce=true leaves an identical copy alone, and the fingerprint, fmt and init writes compare first. docs: field-types.md owns the int-backed enum array description; the port pages point to it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
META-INF/servicesoutput on Java and Kotlin now goes throughGeneratedFileWriter.writeUnmarked, so each file is recorded in the hash manifest. Unchanged bytes are not rewritten, a hand edit is refused by name underhandEdits: keep, and the orphan sweep deletes an untouched file the template no longer renders. A file at such a path with no manifest record is adopted on the first run, since these outputs cannot carry aGENERATEDmarker. The documentation generators also no longer pre-create empty files.mvn metaobjects:eject -Dforce=truecompares before writing: a file, or thecodegen/pom.xml, that already holds the reference bytes is reportedIDENTICALand left untouched.metaobjects:fmt,metaobjects:initand the codegen fingerprint write throughwriteIfChanged. A newGeneratorWritePathTestruns every registered Java and Kotlin generator and fails if a file bypasses the writer or a second run rewrites bytes.docs/features/field-types.md(#int-backed-enum-arrays), with a per-port table. The Java, Kotlin, C#, Python and codegen docs now link there instead of repeating it. The hand-edit rule is likewise stated once indocs/features/own-your-codegen.md.Test step: two lanes were stopped by the out-of-memory killer
The Test step passed with an approved override.
scripts/ci-local.sh --affected --strict-toolchainsran every lane, becausedocs/*changed. The Java reactor, Python, Rust, TypeScript build + typecheck, TypeScript unit suites and the mutation completeness gate were green. Two lanes were killed by the machine's out-of-memory killer (earlyoom SIGTERM) under load from other work on the machine. Neither lane failed a test:typed-create-compile.test.tsworker was killed.Nothing in this diff reaches C# or TypeScript code. The only TypeScript change is a
.gitignorerule plus deleting that killed test's leftover temp directory. The comparison run on the base commit was also killed, so the gate could not attribute failures.This change took one no-mistakes gate run.
Validation
Risk Assessment
✅ Low: The change adds a manifest-aware writeUnmarked path and a behavioral gate (asserting manifest records, per-generator output and zero rewrites on a second run). Prior rounds' findings are fixed, and the eject compare-before-write and docs consolidation trace correctly.
Testing
Drove three JVM scenarios and ran the full Java reactor suite. Template and docs output now joins the hash manifest: unchanged output is not rewritten and a hand edit is refused by name (live driver on the real GeneratedFileWriter). The write-path gate catches both kinds of bypass, shown by an adversarial live driver. The eject goal leaves an identical copy and pom unwritten under -Dforce=true, shown by MetaDataEjectMojoTest, which runs the real mojo in-process. Focused tests pass 57/57. Full
mvn -o testreactor BUILD SUCCESS, 0 failures, though Testcontainers integration-tests are outside this reactor run. The docs consolidation has no runtime surface and was not driven. Overall: pass.Evidence: Live: template/docs output manifest, unchanged rewrite, hand-edit refusal
Evidence: Live adversarial: write-path gate bypass detection
Evidence: Focused JVM tests (Maven)
~/.no-mistakes/evidence/01M7ZGR3Y33361C2CTP9DZHY0P/jvm-reactor-mvn-test.log)Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
server/java/codegen-base/src/test/java/com/metaobjects/generator/util/WritePathGateTest.java:141- WritePathGateTest.every_generator_writes_through_GeneratedFileWriter walks the module source trees and regex-matches the text of every .java/.kt file for write-API names. The test-quality rule bars a test whose only evidence is a source-text match. A regex cannot see a static-import call, Files.move, Files.newByteChannel, FileChannel.open or a write from another helper. The intent requires this gate, so the remedy (not the defect) needs the author's approval. A behavioral alternative would run the real generators in a GeneratedFileWriter capture or manifest run, then assert that every file left on disk appears in run.emittedPaths(). Another option is to keep the scan and extend the forbidden list to the missed APIs. The scanner's own string-input cases (catches_each_way_of_writing_a_file and the like) test the regex, not generator behavior.server/java/maven-plugin/src/main/java/com/metaobjects/mojo/MetaDataEjectMojo.java:634- writeCodegenPomIfNeeded now returns false when the pom already holds identical bytes. printWiring(pomWritten, ...) keys its 'Add this module to the parent pom's <modules>' hint on that value, so a re-run with -Dforce=true over an identical pom no longer prints the hint. Before this change, force printed it. This is a small output regression from the compare-before-write change. Fix: return true (written-or-already-current) for the identical case, or track the 'pom is new' state separately from whether bytes were written.🔧 Fix applied.
4 issues (2 warnings, 2 infos) still open:
server/java/codegen-base/src/test/java/com/metaobjects/generator/util/WritePathGateTest.java:141- WritePathGateTest.every_generator_writes_through_GeneratedFileWriter walks the module source trees and regex-matches the text of every .java/.kt file for write-API names. The test-quality rule bars a test whose only evidence is a source-text match. A regex cannot see a static-import call, Files.move, Files.newByteChannel, FileChannel.open or a write from another helper. The intent requires this gate, so the remedy (not the defect) needs the author's approval. A behavioral alternative would run the real generators in a GeneratedFileWriter capture or manifest run, then assert that every file left on disk appears in run.emittedPaths(). Another option is to keep the scan and extend the forbidden list to the missed APIs. The scanner's own string-input cases (catches_each_way_of_writing_a_file and the like) test the regex, not generator behavior.server/java/maven-plugin/src/main/java/com/metaobjects/mojo/MetaDataEjectMojo.java:634- writeCodegenPomIfNeeded now returns false when the pom already holds identical bytes. printWiring(pomWritten, ...) keys its 'Add this module to the parent pom's <modules>' hint on that value, so a re-run with -Dforce=true over an identical pom no longer prints the hint. Before this change, force printed it. This is a small output regression from the compare-before-write change. Fix: return true (written-or-already-current) for the identical case, or track the 'pom is new' state separately from whether bytes were written.server/java/maven-plugin/src/test/java/com/metaobjects/mojo/GeneratorWritePathTest.java:175- The behavioral gate cannot fail for a generator that regresses to the manifest-lessGeneratedFileWriter.writeIfChanged.writeIfChangeditself adds the path torun.emittedPaths(GeneratedFileWriter.java ~L549), so thefirst.emitted().contains(p)check passes for it, and the second-run check passes too becausewriteIfChangedcompares bytes. That is exactly what the template, mustache, docs and services generators did before this change, and it is the defect the change fixes (no manifest record, no hand-edit refusal). The test, the writer class comment and the CHANGELOG claim the gate stops a generator from 'skipping the hash manifest', but nothing asserts a manifest record. Fix: after the first run, assert each file on disk has a recorded hash, e.g.HashManifest.recordedHash(genState, <path relative to root with forward slashes>) != null. No non-test, non-mojo code callswriteIfChanged, so this holds today. Also assert every registered generator wrote at least one file (track emitted paths per entry): a wrong arg inargs()for one generator currently makes it write nothing and the test still passes, because only the overall disk set is checked non-empty. Round 1's fix introduced this gap; the replacement keeps the original intent's behavioral form, so only the assertion needs tightening.forceOverAnIdenticalPomStillPrintsTheModulesHintcovers it. The write-path changes in the generator bases,TemplateScopeGenerator,MustacheTemplateGenerator,JavaObjectCodeGeneratorand eject IDENTICAL handling trace correctly, as do the consolidated docs (field-types.md owns the int-backed enum-array text and all four port pages point to it; the KNOWN_GAPS relative link resolves). No other defects found.🔧 Fix applied.
2 issues (1 warning, 1 info) still open:
server/java/codegen-base/src/test/java/com/metaobjects/generator/util/WritePathGateTest.java:141- WritePathGateTest.every_generator_writes_through_GeneratedFileWriter walks the module source trees and regex-matches the text of every .java/.kt file for write-API names. The test-quality rule bars a test whose only evidence is a source-text match. A regex cannot see a static-import call, Files.move, Files.newByteChannel, FileChannel.open or a write from another helper. The intent requires this gate, so the remedy (not the defect) needs the author's approval. A behavioral alternative would run the real generators in a GeneratedFileWriter capture or manifest run, then assert that every file left on disk appears in run.emittedPaths(). Another option is to keep the scan and extend the forbidden list to the missed APIs. The scanner's own string-input cases (catches_each_way_of_writing_a_file and the like) test the regex, not generator behavior.forceOverAnIdenticalPomStillPrintsTheModulesHintcovers it. The write-path changes in the generator bases,TemplateScopeGenerator,MustacheTemplateGenerator,JavaObjectCodeGeneratorand eject IDENTICAL handling trace correctly, as do the consolidated docs (field-types.md owns the int-backed enum-array text and all four port pages point to it; the KNOWN_GAPS relative link resolves). No other defects found.scripts/ci-local.sh --affected --strict-toolchainsFocused:mvn -o -pl codegen-base,maven-plugin -am test -Dtest='GeneratedFileWriterTest,GeneratorWritePathTest,MetaDataEjectMojoTest'in server/java — GeneratedFileWriterTest 36/36, GeneratorWritePathTest 1/1, MetaDataEjectMojoTest 20/20, all pass (log: jvm-focused-tests-mvn.log)Live scenario 1 driver: $DEV_SCRATCH disposable program calling real GeneratedFileWriter.beginRun/configureManifest/writeUnmarked over 3 runs — first write WRITTEN with manifest record; identical rerun UNCHANGED with mtime preserved; hand edit + handEdits=keep REFUSED by name, file left as hand-edited (output: jvm-template-output-manifest-live.txt)Live adversarial driver: real GeneratedFileWriter.writeIfChanged and plain Files.writeString inside a Run — writeIfChanged path present in emittedPaths but absent from manifest (manifest assertion needed); plain write absent from emittedPaths (disk-vs-emitted assertion catches it) (output: jvm-gate-bypass-adversary-live.txt)Existing test GeneratorWritePathTest runs every registered Java and Kotlin generator via real execute() over fixtures/persistence-conformance/canonical/meta.fitness.json, checks disk-vs-emitted, manifest records, no silent generators, and zero rewrites on second runExisting test MetaDataEjectMojoTest.forceLeavesAnIdenticalCopyAndPomUnwritten and forceReplacesAnEditedCopyWithTheReference drive real MetaDataEjectMojo.execute() on temp project with mtime assertionsRegression: full Java reactormvn -o test -faein server/java — BUILD SUCCESS, exit 0, 15 modules, 0 failures (log: jvm-reactor-mvn-test.log). Testcontainers integration-tests modules not in this reactor run.Docs consolidation (docs/features/field-types.md, port pages) — not driven, documentation onlyDid not run configuredscripts/ci-local.sh --affected --strict-toolchains; base commit also fails it, and the Java reactor test above covers the JVM lanes.docs/features/own-your-codegen.md- Fixed in this step. The paragraph saying four Java write paths bypass the guard, are never recorded and are never swept was stale. Template, mustache, api/HTML/JSON/PlantUML docs and META-INF/services now go through GeneratedFileWriter.writeUnmarked and are recorded in the hash manifest. Rewritten to describe the unmarked path.docs/features/codegen-concepts.md- Fixed in this step. Said JVM TemplateScopeGenerator writes directly and keeps no manifest record. Now points to own-your-codegen.md, which states the guard.docs/features/migrations/jvm-codegen-hash-manifest.md- Fixed in this step. The 'What does not change' bullet said templates, docs pages and META-INF/services are not recorded. Reworded to 8.1.0 state plus the next release's change, pointing to the CHANGELOG Unreleased entry. Heading renamed to match.docs/features/own-your-codegen.md- Fixed in this step. Eject section did not say an identical reference file is left unwritten under -Dforce. Added one sentence, matching MetaDataEjectMojo's IDENTICAL status.docs/features/field-types.md- Fixed in this step. The consolidated int-backed enum array section said the roundtrip-int-enum-array scenario gates every row, including Java Derby. The scenario's engines are postgres, mysql, sqlite, d1 only (fixtures/persistence-conformance/queries/roundtrip-int-enum-array.yaml). Narrowed the claim and said Derby is not in that corpus. Verified the #int-backed-enum-arrays anchor, the fixture README anchor, the MetaIntEnumArrayColumnType name and the KNOWN_GAPS.md relative link target.fixtures/persistence-conformance/queries/roundtrip-int-enum-array.yaml- Not a documentation defect, so not fixed here. The branch commits six generated test temp files under server/typescript/packages/codegen-ts/test/tmp-typed-create-postgres-IjqOVf/ (Brewer.ts, Brewer.queries.ts, Carrier.ts, Party.ts, Party.queries.ts, caller.ts). They look like leftover output from a Postgres codegen test. Fix: delete the directory from git, have the test write to $DEV_SCRATCH and clean up, and add an ignore rule if needed.🔧 Fix applied.
1 info still open:
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.